﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Data.Entity;

namespace SWGeneracionE.Models.Repositories
{

    public class MemoryRepository<T> : IMemoryRepository<T>
        where T : class
    {


        private List<T> _entities = new List<T>();
        public List<T> Context
        {
            get { return _entities; }
            set { _entities = value; }
        }

        public virtual List<T> GetAll()
        {
            return _entities;
        }

        public List<T> FindBy(Func<T, bool> predicate)
        {
            var query = _entities.Where(predicate);
            return query.ToList<T>();
        }

        public virtual void Add(T entity)
        {
            _entities.Add(entity);
        }

        public virtual void Delete(T entity)
        {
            _entities.Remove(entity);
        }

        public virtual void Save()
        {
            
        }


        private bool disposed = false;
        protected virtual void Dispose(bool disposing)
        {
            if (!this.disposed)
            {
            }

            this.disposed = true;
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

    }

}